package com.xbao.controller;

import com.xbao.core.component.page.Pagination;
import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.Cls;
import com.xbao.model.StuClsRel;
import com.xbao.model.req.ClsReq;
import com.xbao.model.vo.ClsVo;
import com.xbao.model.vo.StuVo;
import com.xbao.service.ClsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/8/24.
 */
@Api(value = "/cls", tags = "cls")
@RequestMapping(value = "cls")
@Controller
@EnableAutoConfiguration
public class ClsController extends BaseController {
    @Resource
    private ClsService clsService;

    /**
     * @param clsCommRequest
     * @return
     */
    @ApiOperation(value = "addCls", notes = "addCls")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public CommResult addCls(@RequestBody CommRequest<Cls> clsCommRequest) {
        clsService.addCls(clsCommRequest.getData());
        return result();
    }

    /**
     * @param clsCommRequest
     * @return
     */
    @ApiOperation(value = "finishCls", notes = "finishCls")
    @RequestMapping(value = "/finish", method = RequestMethod.POST)
    @ResponseBody
    public CommResult finishCls(@RequestBody CommRequest<ClsReq> clsCommRequest) {
        clsService.finish(clsCommRequest.getData());
        return result();
    }

    /**
     * @param clsCommRequest
     * @return
     */
    @ApiOperation(value = "updateCls", notes = "updateCls")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommResult updateCls(@RequestBody CommRequest<ClsReq> clsCommRequest) {
        clsService.updateCls(clsCommRequest.getData());
        return result();

    }

    @ApiOperation(value = "list", notes = "list")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommResult list(@RequestBody CommRequest<ClsReq> clsCommRequest) {
       List<ClsVo> vos= clsService.queryCls(clsCommRequest.getData());
        return new CommResult(vos);

    }

    /**
     * @param clsReqCommRequest
     * @return
     */
    @ApiOperation(value = "stuListOfCls", notes = "stuListOfCls")
    @RequestMapping(value = "/stusOfCls", method = RequestMethod.POST)
    @ResponseBody
    public CommResult<List<StuVo>> stuListOfCls(@RequestBody CommRequest<ClsReq> clsReqCommRequest) {
        return result();
    }

    @ApiOperation(value = "detailCls", notes = "detailCls")
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ResponseBody
    public CommResult detailCls(@RequestBody CommRequest<ClsReq> clsReqCommRequest) {
        ClsVo vo = clsService.detailCls(clsReqCommRequest.getData());
        return new CommResult<ClsVo>(vo);
    }

    @ApiOperation(value = "joinCls", notes = "joinCls")
    @RequestMapping(value = "/joinCls", method = RequestMethod.POST)
    @ResponseBody
    public CommResult joinCls(@RequestBody CommRequest<StuClsRel> clsReqCommRequest) {
         clsService.joinCls(clsReqCommRequest.getData());
        return result();
    }

    @ApiOperation(value = "leaveCls", notes = "leaveCls")
    @RequestMapping(value = "/leaveCls", method = RequestMethod.POST)
    @ResponseBody
    public CommResult leaveCls(@RequestBody CommRequest<StuClsRel> clsReqCommRequest) {
         clsService.leaveCls(clsReqCommRequest.getData());
        return result();
    }


}
